/*
 * @Author: rxn 1003312535@qq.com
 * @Date: 2023-08-30 17:48:56
 * @LastEditors: rxn 1003312535@qq.com
 * @LastEditTime: 2024-10-10 09:33:39
 * @FilePath: \vue3-progect\src\router\setupRouter.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { App } from "vue";
import { createRouter, createWebHashHistory } from "vue-router";
//引入基本路由
import baseRoutes from "@/router/modules/baseRoutes/index.ts"; //基本路由

let router;
let routes = [...baseRoutes];

//注册路由
export const setupRouter = async (app: App<Element>) => {
	createRouterInstance(app);
};

/**
 * 创建路由实例
 * @param app vue实例
 */
const createRouterInstance = (app: App<Element>) => {
	try {
		router = createRouter({
			history: createWebHashHistory(), //createWebHistory()
			routes
		});
		app.use(router);
	} catch (error) {
		console.log("创建路由报错：", error);
	}
};

export { router, routes };
